package com.psp.web.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.web.controller.res.*;
import com.psp.web.controller.res.bean.*;
import com.psp.web.controller.springmvc.req.*;

/**
 * 消息-相关接口
 **/
@Controller
@RequestMapping(value = "/psp/msg", produces = "application/json")
public class SMsgController {
	@Autowired
	com.psp.web.controller.MsgController msgController;

	/**
	 * 获取全部消息
	 **/
	@RequestMapping("/v1/getAll")
	@ResponseBody
	public ListResult<RMsgListBean> getAll(@Validated GetMsgAllParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RMsgListBean> res = new ListResult<RMsgListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return msgController.getAll(param, request, response);
	}

	/**
	 * 交易消息
	 **/
	@RequestMapping("/v1/getExc")
	@ResponseBody
	public ListResult<RExcMsgListBean> getExc(@Validated GetExcMsgParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RExcMsgListBean> res = new ListResult<RExcMsgListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return msgController.getExc(param, request, response);
	}

	/**
	 * 系统消息
	 **/
	@RequestMapping("/v1/getSys")
	@ResponseBody
	public ListResult<RSysMsgListBean> getSys(@Validated GetSysMsgParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RSysMsgListBean> res = new ListResult<RSysMsgListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return msgController.getSys(param, request, response);
	}

	/**
	 * 删除消息
	 **/
	@RequestMapping("/v1/del")
	@ResponseBody
	public BaseResult del(@Validated GetDelMsgParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return msgController.del(param, request, response);
	}
}
